/**
  ******************************************************************************
  * File Name          : stm32f1xx_ModBus_data.c
  * Description        : This file provides code for the MSP Initialization 
  *                      and de-Initialization codes.
  ******************************************************************************
  *
  * COPYRIGHT(c) 2016 STMicroelectronics
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx.h"
#include "stm32f1xx_hal.h"
#include "stm32f1xx_uart.h"

uint16_t gWaterLevel;//cm
uint16_t gWaterMinSpeed;
uint16_t gWaterSpeed = 0;//mm/s
float gWaterFlow;//m3/s
uint16_t gHiWaterFlow;
uint16_t gLoWaterFlow;
uint32_t gWaterSumFlow;//m3/s
uint16_t gHiWaterSumFlow;
uint16_t gLoWaterSumFlow;
uint32_t gBleSumFlow;
//uint8_t gWaterDevAddr;
//uint8_t gWaterBaudrate;
//uint8_t gCanelMode;
//uint16_t gCanelRadius;//cm
//uint16_t gCanelRecWide;//cm
//uint16_t gCanelTrapeWide1;//cm
//uint16_t gCanelTrapeWide2;//cm
//uint16_t gCanelTrapeDepth;//cm
uint16_t gMeterEmptyLevel;//cm
uint16_t gWaterFirstLevel;//cm
uint16_t gMeterRange;//cm
uint16_t gMeterLowRange;//cm
uint16_t gFlowTolerance;//m3/s
uint8_t gMeterStatus;//
uint8_t gClearFlow;

uint16_t g10sRandSpeed = 1;

const modBusAttrRec_t ModBus_Attrs[] = {
  {//0000
    REG_BUS_LEVEL,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gWaterLevel,
  },
  {//0001
    REG_BUS_SPEED,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gWaterSpeed,
  },
  {//0002
    REG_BUS_FLOW_HI,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gHiWaterFlow,
  },
  {//0003
    REG_BUS_FLOW_LO,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gLoWaterFlow,
  },
  {//0004
    REG_BUS_SUMFLOW_HI,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gHiWaterSumFlow,
  },
  {//0005
    REG_BUS_SUMFLOW_LO,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gLoWaterSumFlow,
  },
  {//0006
    REG_BUS_DEVADDR,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT8,
    (void *)&gDevInfo.addr,
  },
  {//0007
    REG_BUS_BAUDRATE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT8,
    (void *)&gDevInfo.baudrate,
  },
  {//0008
    REG_BUS_CNL_MODE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT8,
    (void *)&gCanelParam.mode,
  },
  {//0009
    REG_BUS_CNL_R,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gCanelParam.radius,
  },
  {//000A
    REG_BUS_CNL_RECTWIDE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gCanelParam.recWide,
  },
  {//000B
    REG_BUS_CNL_TRAPEZIUM_1WIDE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gCanelParam.trapeDown,
  },
  {//000C
    REG_BUS_CNL_TRAPEZIUM_2WIDE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gCanelParam.trapeUp,
  },
  {//000D
    REG_BUS_CNL_TRAPEZIUM_DEPTH,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gCanelParam.depth,
  },
  {//000E
    REG_BUS_EMPTY_BACKUP,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gMeterEmptyLevel,
  },
  {//000F
    REG_BUS_RANGE_BACKUP,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gMeterRange,
  },
  
  {//0029
    REG_BUS_FIRST_LEVEL,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gWaterFirstLevel,
  },
  {//002A
    REG_BUS_EMPTY_LEVEL,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gMeterEmptyLevel,
  },
  {//002B
    REG_BUS_RANGE,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gMeterRange,
  },
  {//002C
    REG_BUS_LOW_RANGE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gMeterLowRange,
  },
  {//002D
    REG_BUS_RANGE_TOLERANCE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gFlowTolerance,
  },
  {//002E
    REG_BUS_METER_STATUS,
    ACCESS_CONTROL_READ,
    DATATYPE_UINT16,
    (void *)&gMeterStatus,
  },
  {//002F
    REG_BUS_CLEAR_FLOW,
    ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gClearFlow,
  },
  //Set Speed
  {//0250
    REG_SPEED_SENSITIVITY,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gReadSpeed.sentivity,
  },
  {//0252
    REG_SPEED_ANGLE,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gReadSpeed.angle,
  },
  {//025C
    REG_SPEED_GAIN,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gReadSpeed.gain,
  },
  {//025E
    REG_SPEED_POWER,
    ACCESS_CONTROL_READ|ACCESS_CONTROL_WRITE,
    DATATYPE_UINT16,
    (void *)&gReadSpeed.power,
  },
};

const uint8_t C_MODBUS_ATTR_SIZE  = sizeof(ModBus_Attrs)/sizeof(ModBus_Attrs[0]);

/**
  * @}
  */

/**
  * @}
  */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
